package com.ytjj.common.utils;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.ytjj.common.constants.AlipayCertConstants;
import com.ytjj.common.constants.AlipayConstants;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description 支付宝支付工具类
 *
 * @Version 1.0
 *
 */
@Service
public class AlipayByCertUtil {
    @Resource
    private AlipayConstants alipayConstants;
    @Resource
    private AlipayCertConstants alipayCertConstants;

    public AlipayClient getAlipayClient() {
        // 向支付宝发送支付请求
        // 1. 封装RSA签名方式
        //获得初始化的AlipayClient
        AlipayClient alipayClient = new DefaultAlipayClient
                (alipayConstants.getGATEWAY_URL(),
                        alipayCertConstants.getAPPID(),
                        alipayConstants.getRSA_PRIVATE_KEY(),
                        alipayConstants.getFORMAT(),
                        alipayConstants.getCHARSET(),
                        alipayConstants.getALIPAY_PUBLIC_KEY(),
                        alipayConstants.getSIGNTYPE());
        return alipayClient;
    }
}
